﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cos.Core.Model.Template;
using Cos.Module.Template.Data;
using Microsoft.Practices.Unity;

namespace Cos.Module.Template
{
    public class TemplateService : ITemplateService
    {
        private readonly ITemplateRepository templateRepository;
        private readonly IPartRepository partRepository;
        private readonly IDataTypeRepository dataTypeRepository;

        /// <summary>
        /// To be used for injection
        /// </summary>
        /// <param name="templateRepository"></param>
        [InjectionConstructor]
        public TemplateService(ITemplateRepository templateRepository, IPartRepository partRepository, IDataTypeRepository dataTypeRepository)
        {
            this.templateRepository = templateRepository;
            this.partRepository = partRepository;
            this.dataTypeRepository = dataTypeRepository;
        }

        public Cos.Core.Model.Template.Template GetTemplate(int templateId)
        {
            return this.templateRepository.GetTemplate(templateId);
        }

        public IEnumerable<Core.Model.Template.Template> GetTemplates()
        {
            return templateRepository.GetTemplates();
        }

        public Cos.Core.Model.Template.Template SaveTemplate(Cos.Core.Model.Template.Template template)
        {
            return this.templateRepository.SaveTemplate(template);
        }

        public Part GetPart(int partId)
        {
            return partRepository.GetPart(partId);
        }

        public Part GetPart(int templateId, string partName)
        {
            return this.partRepository.GetPart(templateId, partName);
        }

        public IEnumerable<Part> GetParts(int templateId)
        {
            return this.partRepository.GetParts(templateId);
        }

        public Part SavePart(Part part)
        {
            return this.partRepository.SavePart(part);
        }

        public DataType GetDataType(int dataTypeId)
        {
            return this.dataTypeRepository.GetDataType(dataTypeId);
        }

        public IEnumerable<DataType> GetDataTypes()
        {
            return this.dataTypeRepository.GetDataTypes();
        }

        public DataType SaveDataType(DataType dataType)
        {
            return this.dataTypeRepository.SaveDataType(dataType);
        }
    }
}
